import { http } from '@/utils/http';
import { getWxUserId } from '@/utils/auth';
import { useAuthStore } from '@/stores';
import type { AnyObj } from '@/types/global';

const appId = import.meta.env.VITE_APP_ID;


/**
 * {"code":200,"msg":"操作成功","data":
 * {"orderId":"1805835689759485954",
 * "payNo":"8994380313591877",
 * "timeStamp":"1719379754",
 * "nonceStr":"gpX0d6x8OVadwsK5FDRxs4lytisecYOe",
 * "packageValue":"prepay_id=wx26132914532733fb6ac94ef06938440000",
 * "signType":"RSA",
 * "paySign":"bDRNImT9RlxA0wU2M00T9vHLl/rxuO5T9JtSmyDNFVEEZrmk7r78AahqupTiMtLGBgnA8bg009kS6BLFHCmEWxsIlHmFRIYOslK2tlIpfFHxzokov2BjbGbPyfOGPCZPbqTSzf1kMVV+k9uwR891/Wx58AlzFzQnuPE75XMSx6uRlM/gkU5ByloAF/dK9cVKlR9HBipyaxube7lOOwrSrerJIPyYVTScLWBg+5tYt0fp0EPLWFBHfDzpIKmW82i1sb5SAXUxBxoa/yYORTR8rPsrJPtYPtkiA6Qb8N6VfpEVO+lWkqBtIm8puFls7D0+cd9OMpzvnGdSIMk5kEGy5g=="}}
 */
export const submitOrder = (data : AnyObj) => {
	const authStore = useAuthStore() as any;
	data.appId = appId;
	data.openId = authStore.profile.openId;
	data.wxUserId = authStore.profile.userId;
	return http<AnyObj>({
		method: 'POST',
		url: `/wx/trade/submitOrder`,
		data
	});
}


export const complatedOrder = (orderId : string) => {
	const wxUserId = getWxUserId();
	return http<AnyObj>({
		method: 'POST',
		url: `/wx/trade/completedOrder`,
		data: {
			orderId,
			wxUserId
		}
	});
}


export const getOrderList = (data : AnyObj) => {
	const userId = getWxUserId();
	return http<AnyObj[]>({
		method: 'GET',
		url: `/wx/trade/listOrder`,
		data: {
			...data,
			userId
		}
	});
}

export const getOrderDetail = (orderId : string) => {
	return http<AnyObj>({
		method: 'GET',
		url: `/wx/trade/${orderId}`,
	});
}